<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>工艺卡校对</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-special">类型</label>
                                    <select id="query-special" class="form-control" name="special">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${specials}" th:value="${type.name}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawNo">图号</label>
                                    <input id="query-drawNo" type="text" name="drawNo" class="form-control"
                                           placeholder="请输入图号">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawName">图名</label>
                                    <input id="query-drawName" type="text" name="drawName" class="form-control"
                                           placeholder="请输入图名">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="">请选择</option>
                                        <option value="1">待提交</option>
                                        <option value="2" selected>待转定额</option>
                                        <option value="3">待定额提交</option>
                                        <option value="4">待转生产</option>
                                        <option value="5">已转生产</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query2-isCheck">校对</label>
                                    <select id="query2-isCheck" class="form-control" name="isCheck">
                                        <option value="">全部</option>
                                        <option value="0">未校对</option>
                                        <option value="1">已校对</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <div id="toolbar" class="form-inline">
                        <a shiro:hasPermission="est:verify:quota" href="javascript:void(0);"
                           class="btn btn-success pull-right" style="margin-right: 10px" onclick="quotaAll()">
                            <span class="Bold">批量转定额</span>
                        </a>
                    </div>
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    function refreshTable() {
        js.table.refresh(table);
    }

    /** 转定额 */
    function quota(id) {
        js.modal.confirm("确认转定额吗？", function () {
            js.post({
                url: ctx + "est/verify/quota",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 批量转定额 */
    function quotaAll() {
        let arr = js.table.selectColumns(table, "id");
        if (arr.length < 1) {
            js.modal.alert("请选择内容");
            return;
        }
        js.modal.confirm("确认转定额吗？", function () {
            js.post({
                url: ctx + "est/verify/quotaAll",
                data: {
                    ids: arr
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 取消转定额 */
    function cancel(id) {
        js.modal.confirm("确认取消转定额吗？", function () {
            js.post({
                url: ctx + "est/verify/cancelQuota",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    $(function () {

        /** 子表 */
        table = js.table.init({
            id: "bootstrap-table",
            escape: true,
            url: ctx + "est/verify/list",
            columns: [
                {
                    checkbox: true,
                    formatter: function (value, row) {
                        if (row.status === 2 && row.isCheck === 1) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "项目数量", field: 'proNum'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "图号", field: 'drawNo'},
                {title: "图名", field: 'drawName'},
                {title: "状态", field: 'status',
                    formatter: function (value, row) {
                        if (value === 1) {
                            return '<span class="badge label-inverse">待提交</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">待转定额</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-warning">待提交二审核</span>';
                        } else if (value === 4) {
                            return '<span class="badge label-warning">已提交待审</span>';
                        } else if (value === 5) {
                            return '<span class="badge label-success">已转生产</span>';
                        }
                    }
                },
                {title: "校对状态", field: 'isCheck',
                    formatter: function (value) {
                        if (value === 0) {
                            return '<span class="badge label-default">未校对</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已校对</span>';
                        }
                    }
                },
                {title: "工艺科室", field: 'branchName'},
                {title: "创建人", field: 'createNameOne'},
                {title: "驳回原因", field: 'rejectReason',
                    formatter: function (value, row) {
                        if (value) {
                            return '<span class="text-red">' + value + '</span>';
                        }
                    }
                },
                {title: "提报日期", field: 'createTime'},
                {title: "是否变更", field: 'mayChange',
                    formatter: function (value, row) {
                        if (value) {
                            return '是';
                        } else {
                            return '否'
                        }
                    }
                },
                {
                    title: "操作",
                    // width: '160px',
                    formatter: function (value, row) {
                        let actions = [];
                        if (hasP('est:verify:edit') && row.status === 2) {
                            // actions.push('<a class="btn btn-warning btn-xs" target="_blank" href="' + ctx + 'est/verify/' + row.id + '" > 校对</a>');
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0);" onclick="javascript:window.open(\'' + ctx + 'est/verify/' + row.id + '\')" > 校对</a>');
                        }
                        if (hasP('est:verify:quota') && row.status === 2 && row.isCheck === 1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="quota(' + row.id + ')"> 转定额</a>');
                        }
                        /*if (hasP('est:verify:cancel') && row.status === 3) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancel(' + row.id + ')"> 撤消</a>');
                        }*/
                        return actions.join('');
                    }
                }
            ]
        });

    });
</script>
</body>
</html>
